import xml.sax
from XML.XMLFetcher import XMLFetcher
from XML.XMLCapabilitiesParser import XMLCapabilitiesParser
from XML.XMLLayerParser import XMLLayerParser

class XMLHandler(object):

    parser = xml.sax.make_parser()
    xmlfetcher = XMLFetcher()
    capabilities_handler = XMLCapabilitiesParser()
    layer_handler = XMLLayerParser()
    
    def __init__(self):
        ''''''
    
    def load_capabilities(self, url):
        try:
            self.capabilities_handler.attributes = []
            self.parser.setContentHandler(self.capabilities_handler)
            xml = self.xmlfetcher.fetch_xml(url)
            self.parser.parse(xml)
        except AttributeError:
            print("Object has no attribute")
    
    def load_layer(self, url, tile_seed):
        try:
            tile_seed.tile_schema.resolutions = []
            self.layer_handler.tile_seed = tile_seed
            self.parser.setContentHandler(self.layer_handler)
            xml = self.xmlfetcher.fetch_xml(url)
            self.parser.parse(xml)
        except AttributeError:
            print("Object has no attribute")